#include<stdio.h>
#include<string.h>

// i am from nanjing
// gnijnan morf ma i    整句话逆序
// nanjing from am i    每个单词单独逆序
void Reserve(char*s,int len)
{
    //首尾互换
    for(int i = 0; i < len / 2 ; i++)
    {
        char temp = s[i];
        s[i] = s[len -1-i];
        s[len -1-i] = temp;
    }
}

void Reserve2(char*s,int len)
{ 
    int count = 0;
    for(int i = 0; i <= len ; i++)
    {
       
        if(s[i] == ' ' || s[i] == '\0')
        {
            //一个单词逆序
            Reserve(s+i-count,count);
            //重新开始计算下一个字符串的长度 
            count=0;
        }
        else
        count++;//数一个数放上去 正常字符
    }
}


int main()
{

    char s[] ="i am from nanjing";
    Reserve(s,strlen(s));
    printf("%s\n",s);
    Reserve2(s,strlen(s));
    printf("%s\n",s);
    


    return 0;
}